#include <stack>
#include <queue>
#include <vector>

template<typename T>
class SomeMachine {
    std::vector<std::queue<T>> in;
    std::stack<T> box;
    int box_capacity;
    std::vector<T> out;

public:
    SomeMachine() = delete;
    SomeMachine(int N, int capacity) : in(N), box_capacity(capacity) {}
    auto pop_queue(int i) {
        if (in[i].empty()) return;
        if (box.size() == box_capacity) {
            // if box is full
            this->pop_box();
        }
        box.push(in[i].front());
        in[i].pop();
    }
    auto pop_box() {
        if (box.empty()) return;
        out.push_back(box.top());
        box.pop();
    }
    auto push_queue(int i, T item) {
        in[i].push(item);
    }
    auto& get_output() {
        return out;
    }
    auto clear_outpot() {
        out.clear();
    }
};

#include <iostream>

int main() {
    int N, M, capacity;
    std::cin >> N >> M >> capacity;

    SomeMachine<char> machine(N, capacity);

    for (int i = 0; i < N; ++i) {
        std::string line;
        std::cin >> line;
        for (auto c : line) {
            machine.push_queue(i, c);
        }
    }

    int op;

    do {
        std::cin >> op;
        if (op == -1) break;
        if (op > 0) {
            machine.pop_queue(op - 1);
        }
        if (op == 0) {
            machine.pop_box();
        }
    } while (true);
    
    auto out = machine.get_output();

    for (auto item : out) {
        std::cout << item;
    }
}
